<template>
	<view>
		<cu-custom :isBack="true" bgColor="bg-white">
			<block slot="backText"></block>
			<block slot="content"><text>分红兑换</text></block>
		</cu-custom>
		
		<view class="whole-box" >
			<view class="gold-black-box">
				
				<view class="top-box">
					<!-- <image class="top-box-bg" src="@/static/black_bg/stander-box.png" mode="aspectFill"></image> -->
					<view class="top-box-content">
						<view class="note-price">
							<text class="note">可用趣豆</text>
							<text class="price text-price">{{user_been}}</text>
						</view>
						<!-- <image class="icon-gold-tixian" src="@/static/icon-gold-money.png" mode="aspectFill"></image> -->
					</view>
				</view>
				
				<view class="my-data-box">
					<!-- <image class="my-data-box-bg" src="@/static/black_bg/stander-box.png" mode="aspectFill"></image> -->
					<view class="my-data-box-content-inputbox">
						<!-- <view class="title">请选择充值金额</view> -->
						<view class="type-box">
							<text class="cur">{{mode==1?'余额兑换':'分红权兑换'}}</text>
						</view>
						<view class="price-list" v-if="mode==1">
							<view v-for="(item,index) in been_integral_config" :key="index" class="price-box" :class="cur==index?'cur':''" @tap="selectIntegral(index)">
								<text class="price">{{item.pindou}}趣豆</text>
								<text class="award">{{item.integral}}余额</text>
							</view>
						</view>
						<view class="price-list" v-else>
							<view v-for="(item,index) in been_integral_weight_config" :key="index" class="price-box" :class="cur==index?'cur':''" @tap="selectIntegral(index)">
								<text class="price">{{item.pindou}}趣豆</text>
								<text class="award">{{item.integral_weight}}分红权</text>
							</view>
						</view>
					</view>
				</view>
				
				<view class="my-data-box-submitbox">
					<!-- <image class="my-data-box-bg-submitbox" src="@/static/black_bg/stander-box.png" mode="aspectFill"></image> -->
					<view class="my-data-box-content-submitbox">
						
						<view class="input-box">
							<text>可兑换{{mode==1?'余额':'分红权'}}</text>
							<input type="digit" placeholder-class="my-input-holder" v-model="integral" disabled="disabled"></input>
						</view>
						<button @tap="submitApply">提交</button>
					</view>
				</view>
				
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				member: null,
				theme: this.$config.THEME(),
				checkLoading: false,
				user_been: 0,
				
				mode: 1, //1余额，2分红权
				been_integral_config: [],
				been_integral_weight_config: [],
				
				cur: 0,
				prices:[],
				been: 0, //趣豆
				integral: 0, //转换值
			}
		},
		onLoad() {
			if (this.$common.loginAuth(true)) {
				this.$common.getMember().then((member) => {
					this.member = member
					this.getTotal();
				})
			}
		},
		onShow() {
			if (this.$common.loginAuth(true)) {}
		},
		methods: {
			selectIntegral(index){
				this.cur = index
				if(this.mode==1){
					this.been = this.been_integral_config[this.cur].pindou
					this.integral = this.been_integral_config[this.cur].integral
				}else{
					this.been = this.been_integral_weight_config[this.cur].pindou
					this.integral = this.been_integral_weight_config[this.cur].integral_weight
				}
			},
			getTotal() {
				this.$http
					.get('integral_info', {})
					.then((response) => {
						this.user_been = response.data.data.user_been
						this.mode = parseInt(response.data.data.been_exchange_mode)
						this.been_integral_config = response.data.data.been_integral_config
						this.been_integral_weight_config = response.data.data.been_integral_weight_config
						this.selectIntegral(0)
					})
					.catch((response) => {
						console.log(response)
					})
			},
			submitApply(){
				let integral = this.integral;
				let been = this.been
				if (!integral || !been) {
					this.$common.showError('请选择指定趣豆进行兑换')
					return
				}
				if (been > parseFloat(this.user_been)) {
					this.$common.showError('趣豆不足')
					return
				}
				uni.showModal({
					title: '趣豆的兑换',
					content: '是否确定兑换?',
					success: (res) => {
						if(res.confirm){
							if(this.checkLoading) return
							this.checkLoading = true
							uni.showLoading({
								title: '处理中'
							})
							this.$http.post('been_to_money', {
								mode: this.mode,
								been: been
							}).then((response) => {
								uni.hideLoading()
								this.checkLoading = false
								this.$common.showSuccess('兑换成功')
								this.getTotal()
							}).catch((response) => {
								uni.hideLoading()
								this.checkLoading = false
							})
						}
					}
				})
				
			},
		},
	}
</script>

<style>
	.uni-input-input{
		background: none!important;
	}
	.whole-box{
		background-image: url(../../../static/new-back.png);
		background-size: 100% 100%;
		min-height: calc(100vh - 45px);
		padding: 25rpx 0;
	}
	.gold-black-box{
		padding: 25rpx 0;
		margin: 0 10rpx;
		/* border: 2rpx solid #999999; */
		border-radius: 30rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	
	.gold-black-box .top-box{
		/* margin-top: 25rpx; */
		width: 690rpx;
		height: 276rpx;
		/* border: 2rpx solid #999999; */
		border-radius: 30rpx;
		overflow: hidden;
		position: relative;
		background-color: #ffffff;
	}
	.top-box .top-box-bg{
		width: 100%;
		height: 100%;
	}
	.top-box .top-box-content{
		width: 690rpx;
		/* height: 276rpx; */
		position: absolute;
		left: 0;
		top: 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 30rpx;
		padding: 0 30rpx;
	}
	.top-box-content .note-price{
		flex: 1;
		height: 102rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}
	.note-price .note{
		font-size: 36rpx;
		font-weight: bold;
		color: #1A181E;
	}
	.note-price .price{
		font-size: 38rpx;
		font-weight: bold;
		color: #1A181E;
	}
	.top-box-content .icon-gold-tixian{
		width: 92rpx;
		height: 106rpx;
		flex-shrink: 0;
		margin-left: 20rpx;
	}
</style>

<style>
	.gold-black-box .my-data-box{
		margin-top: 25rpx;
		width: 690rpx;
		height: 570rpx;
		/* border: 2rpx solid #999999; */
		border-radius: 30rpx;
		overflow: hidden;
		position: relative;
		background-color: #ffffff;
	}
	.my-data-box .my-data-box-bg{
		width: 100%;
		height: 100%;
	}
	.my-data-box .my-data-box-content-inputbox{
		width: 690rpx;
		position: absolute;
		left: 0;
		top: 0;
		padding: 30rpx 40rpx;
	}

	.my-data-box-content-inputbox .title{
		font-size: 32rpx;
		color: #E9CFA4;
	}
	
	.my-data-box-content-inputbox .type-box{
		display: flex;
		justify-content: space-around;
		align-items: center;
		
	}
	.type-box text{
		padding: 0 20rpx;
		height: 50rpx;
		line-height: 50rpx;
		text-align: center;
		font-size: 32rpx;
		color: #1A181E;
	}
	.type-box text.cur{
		/* border-bottom: 2rpx solid #E9CFA4; */
	}
	
	.my-data-box-content-inputbox .change-box{
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.change-box input{
		margin: 120rpx 0rpx;
		font-size: 40rpx;
		color: #FFFFFF;
		text-align: center;
	}
	.change-box .tips{
		align-self: flex-start;
		margin-top: 20rpx;
		font-size: 28rpx;
		font-weight: bold;
		color: #E9CFA4;
	}
	.change-box .tips text{
		margin-left: 10rpx;
		font-size: 26rpx;
		font-weight: bold;
		color: #FFFFFF;
	}
	
	.my-data-box-content-inputbox .price-list{
		display: flex;
		flex-wrap: wrap;
		align-items: center;
	}
	.price-list .price-box{
		margin-right: 24rpx;
		margin-top: 50rpx;
		width: 185rpx;
		height: 104rpx;
		border-radius: 20rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		background-color: #EEEEEE;
		color: #3C3A3A;
		font-size: 34rpx;
	}
	.price-list .price-box:nth-child(3n){
		margin-right: 0
	}
	.price-list .price-box.cur{
		background: #1A181E;
		color: #ffffff!important;
	}
	.price-box .price{
	}
	.price-list .price-box.cur .price{
		
	}
	.price-list .award{
		color: #ff0000;
		font-size: 30rpx;
	}
	.price-box.cur .award{
		color: #ffffff!important;
	}
	
	.other-box{
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
	.price-holder{
		padding: 0 10rpx;
		font-size: 32rpx;
		color: #999999;
	}
	.price-input{
		padding: 0 10rpx;
		font-size: 32rpx;
		color: #FF0000;
		font-weight: bold;
		text-align: center;
	}
</style>

<style>
	.change-btn button{
		margin-top: 30rpx;
		margin-bottom: 60rpx;
		padding: 0;
		width: 604rpx;
		height: 90rpx;
		background-color: #E9CFA4;
		border-radius: 45rpx;
		line-height: 90rpx;
		font-size: 40rpx;
		color: #000000;
	}
	.change-btn button::after{
		border: 0;
	}
	.gold-black-box .my-data-box-submitbox{
		margin-top: 25rpx;
		width: 690rpx;
		height: 240rpx;
		/* border: 2rpx solid #999999; */
		border-radius: 30rpx;
		overflow: hidden;
		position: relative;
		background-color: #ffffff;
	}
	.my-data-box-submitbox .my-data-box-bg-submitbox{
		width: 100%;
		height: 100%;
	}
	.my-data-box-submitbox .my-data-box-content-submitbox{
		width: 690rpx;
		position: absolute;
		left: 0;
		top: 0;
		padding: 30rpx 40rpx;
	}
	.my-data-box-content-submitbox .input-box{
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.input-box text{
		font-size: 32rpx;
		font-weight: bold;
		color: #1A181E;
	}
	.input-box input{
		text-align: right;
		font-size: 32rpx;
		color: #1A181E;
		border-bottom: 1rpx solid #1A181E;
	}
	.my-input-holder{
		font-size: 18rpx;
		color: #9B9B9B;
	}
	
	.pay-list .payment{
		margin-top: 40rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.payment image{
		width: 40rpx;
		height: 40rpx;
		margin-right: 20rpx;
		flex-shrink: 0;
	}
	.payment text{
		flex: 1;
		font-size: 30rpx;
		font-weight: bold;
		color: #E9CFA4;
	}
	.payment .action{
		
	}
	.my-data-box-content-submitbox button{
		margin-top: 60rpx;
		padding: 0;
		width: 224rpx;
		height: 60rpx;
		background-color: #1A181E;
		box-shadow: 0px 2rpx 0px 0px rgba(91, 82, 67, 0.5);
		border-radius: 30rpx;
		line-height: 60rpx;
		font-size: 30rpx;
		color: #ffffff;
	}
	.my-data-box-content-submitbox button::after{
		border: 0;
	}
</style>